﻿@{
    ViewData["Title"] = "任务调度管理";
}
<style>
    .layui-form-label { width: 120px; }
    .layui-input-block { margin-left: 150px }</style>
<div class="layui-layout layui-layout-admin">

    <form class="layui-form" action="" lay-filter="val-filter">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">触发器编号</label>
                <div class="layui-input-inline">
                    <input type="hidden" name="id" value="0">
                    <input type="hidden" name="jobId" value="">
                    <input type="text" name="triggerId" autocomplete="off" lay-verify="required" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">触发器类型</label>
                <div class="layui-input-inline">
                    <select name="triggerType">
                        <option value="Furion.Schedule.PeriodTrigger">间隔</option>
                        <option value="Furion.Schedule.CronTrigger">Cron表达式</option>
                    </select>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">间隔时间(ms)</label>
            <div class="layui-input-block">
                <input type="number" value="1" lay-affix="number" name="periodValue" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">Cron表达式</label>
            <div class="layui-input-block">
                <input type="text" name="args" autocomplete="off" lay-verify="required" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">起始时间</label>
                <div class="layui-input-inline">
                    <input type="text" name="startTime" id="startTime" autocomplete="off" lay-verify="date" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">结束时间</label>
                <div class="layui-input-inline">
                    <input type="text" name="endTime" id="endTime" autocomplete="off" lay-verify="date" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">最大触发次数</label>
                <div class="layui-input-inline">
                    <input type="number" value="1" lay-affix="number" name="maxNumberOfRuns" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">最大出错次数</label>
                <div class="layui-input-inline">
                    <input type="number" value="1" lay-affix="number" name="maxNumberOfErrors" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">重试次数</label>
                <div class="layui-input-inline">
                    <input type="number" value="1" lay-affix="number" name="numRetries" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">重试间隔(ms)</label>
                <div class="layui-input-inline">
                    <input type="number" value="1" lay-affix="number" name="retryTimeout" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">立即启动</label>
                <div class="layui-input-inline">
                    <input type="radio" name="startNow" value="true" title="是" checked>
                    <input type="radio" name="startNow" value="false" title="否">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">启动时执行一次</label>
                <div class="layui-input-inline">
                    <input type="radio" name="runOnStart" value="true" title="是" checked>
                    <input type="radio" name="runOnStart" value="false" title="否">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">重置触发次数</label>
            <div class="layui-input-block">
                <input type="radio" name="resetOnlyOnce" value="true" title="是" checked>
                <input type="radio" name="resetOnlyOnce" value="false" title="否">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">描述信息</label>
            <div class="layui-input-block">
                <textarea name="description" class="layui-textarea"></textarea>
            </div>
        </div>
    </form>

</div>

@section scripts {
    <script type="text/javascript">
        var app = {};
        layui.use(['http', 'toast'], function () {
            var form = layui.form, $ = layui.$, laydate = layui.laydate,
                http = layui.http, toast = layui.toast;
            //
            app.init = function () {
                var data = app.data || {};
                form.val('val-filter', data);
                laydate.render({ elem: '#startTime' });
                laydate.render({ elem: '#endTime' });

                $('input[name=startNow][value=' + data.startNow + ']').prop('checked', true);
                $('input[name=runOnStart][value=' + data.runOnStart + ']').prop('checked', true);
                $('input[name=resetOnlyOnce][value=' + data.resetOnlyOnce + ']').prop('checked', true);
                form.render('radio');
            }();
            app.save = function () {
                form.submit('val-filter', function (data) {
                    var postData = data.field
                    //
                    var url = postData.id == '0' ? '/api/sysJob/addJobTrigger' : '/api/sysJob/UpdateJobTrigger'
                    http.post(url, postData).then((res) => {
                        if (res.code == 200) {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload('lsttable');
                            toast.success({ message: '保存成功！' });
                        }
                        else {
                            layer.alert('保存失败，错误信息:' + res.message, { icon: 2 });
                        }
                    });
                    return false;
                });
            }
        })
    </script>
}
